package org.forum.dao.impl;

import java.io.Serializable;
import java.util.List;

import org.forum.dao.ForumDao;
import org.forum.dao.base.BaseDaoImpl;
import org.forum.domain.Forum;
import org.forum.domain.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ForumDaoImpl extends BaseDaoImpl<Forum> implements ForumDao{

	Logger logger = LoggerFactory.getLogger(ForumDaoImpl.class);
	
	@Override
	public List<Forum> getHighProfileForum(int pageNo,int pageSize) {
		String hql = "SELECT en FROM forum en" + " ORDER BY en.numberOfFollows DESC";
		List<Forum> forums = findByPage(hql,pageNo, pageSize);
		if(logger.isDebugEnabled()){
			logger.debug(forums.toString());
		}
		return forums;
	}

	@Override
	public int getAdministrationIdByForumId(int forumId) {
		String hql = "SELECT en FROM Forum en " + "WHERE en.forumId=" + forumId;
		List<Forum> forums = find(hql);
		return forums.get(0).getAdministratorId();
	}

	@Override
	public User getAdministrationInfoByAdministrationId(int administrationId) {
		
		return null;
	}

	@Override
	public Serializable addForum(Forum forum) {
		return save(forum);
	}

	@Override
	public void updateForum(Forum forum) {
		update(forum);
	}

	@Override
	public void deleteForum(Forum forum) {
		delete(forum);
	}

	@Override
	public List<Forum> getForumsByUserId(User user) {
		return null;
	}
}
